﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ATW.MT.CommonClass;
using ATW.MT.BUS;
using System.Data;

namespace ATW.MT
{
    public partial class SiteMaster : System.Web.UI.MasterPage
    {
        UserInfo u = new UserInfo();
        bus_D_user user = new bus_D_user();
        DataTable menu = new DataTable();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserInfo"] == null)
            {
                Response.Redirect("../Main/Login.aspx");
            }
            else
            {
                u = (UserInfo)Session["UserInfo"];
                lblUser.Text = u.UserAccount;
            }
            if (!IsPostBack)
            {
                initMenu();
            }
        }
        /// <summary>
        /// 根据权限启用菜单(不完善，待修改)
        /// </summary>
        private void initMenu()
        {
            try
            {
                menu = user.getModuleList(u.UserId);
                if (menu != null && menu.Rows.Count > 0)
                {
                    DataView dv = menu.DefaultView;
                    dv.RowFilter = "module_level='1'";
                    menu_1.DataSource = dv.ToTable();
                    menu_1.DataBind();

                }
                else
                {
                    Server.Transfer("../Default/Unauthoried.aspx");
                }
            }
            catch (Exception ex)
            {

            }
        }
        protected void menu_1_OnItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Repeater menu_2 = (Repeater)e.Item.FindControl("menu_2");
                HiddenField hdf = (HiddenField)e.Item.FindControl("hdfMenuid");
                if (menu_2 != null && hdf != null)
                {
                    DataView dv = menu.DefaultView;
                    dv.RowFilter = "module_level='2' and father_id='" + hdf.Value + "'";
                    menu_2.DataSource = dv.ToTable();
                    menu_2.DataBind();
                }

            }
        }
        /// <summary>
        /// 注销
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void lbnLogOut_Click(object sender, EventArgs e)
        {
            Session["UserInfo"] = null;
            Server.Transfer("../Main/Login.aspx");
        }
    }
}
